<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据字典管理</title>
<#include "../common/link.ftl"/>
    <script>
        $(function () {
            $('.btn-input').click(function () {
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    //将数据填充到表单中
                    $('input[name=id]').val(json.id);
                    $('input[name=sn]').val(json.sn);
                    $('input[name=title]').val(json.title);
                    $('input[name=intro]').val(json.intro);
                }
                //打开模态框
                $('#editModal').modal("show");
            })


            $('.btn-submit').click(function () {
                //将表单的请求方式修改为异步请求
                //后台一定是响应json字符串回来
                $('#editForm').ajaxSubmit(function (data) {
                    console.log(data);
                    if (data.success) {
                        $.messager.alert("温馨提示", "执行成功,2s后自动刷新");
                        //2秒后自动关闭
                        setTimeout(function () {
                            //刷新本页面
                            window.location.reload();
                        }, 1600);
                        alert("恭喜你,保存成功");
                    } else {
                        $.messager.alert(data.msg);
                    }
                })
            })

        })

    </script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "../common/navbar.ftl"/>
    <!--菜单回显-->
<#assign currentMenu="systemDictionary"/>
<#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>数据字典管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/systemDictionary/list.do" method="post">
                <#--分页查询的关键-->
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <a href="javascript:;" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>数据字典标题</th>
                            <th>数据字典编号</th>
                            <th>数据字典简介</th>
                            <th>操作</th>
                        </tr>
                    <#--list,要遍历的集合 as 变量-->
                    <#list pageResult.list as entity>
                        <tr>
                        <#--从0开始,需要加1-->
                            <td>${entity_index + 1}</td>
                            <td>${entity.sn}</td>
                            <td>${(entity.title)!}</td>
                            <td>${entity.intro}</td>
                            <td>
                                <a class="btn btn-info btn-xs btn-input" href="javascript:;"
                                   data-json='${entity.jsonString}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>

                            </td>
                        </tr>
                    </#list>
                    </table>
                    <!--分页-->
                <#include "../common/page.ftl"/>
                </div>
            </div>
        </section>
    </div>
<#include "../common/footer.ftl"/>
</div>


<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">数据字典添加/编辑</h4>
            </div>
            <div class="modal-body">
                <form action="/systemDictionary/saveOrUpdate.do" method="post" id="editForm">
                    <input id="id" name="id" type="hidden">

                    <div class="form-group">
                        <label for="exampleInputEmail1">数据字典标题</label>
                        <input type="title" class="form-control" id="inputDeptName" name="title" placeholder="数据字典名称">
                    </div>

                    <div class="form-group">
                        <label for="exampleInputPassword1">数据字典编号</label>
                        <input type="sn" class="form-control" id="inputDeptSn" name="sn" placeholder="数据字典编号">
                    </div>

                    <div class="form-group">
                        <label for="exampleInputEmail1">数据字典简介</label>
                        <input type="intro" class="form-control" id="inputDeptName" name="intro" placeholder="数据字典简介">
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>

